package com.fingard.dsp.bank.directbank.spdb01;

import java.sql.Connection;
import java.util.*;

import com.fingard.FGBiz;
import com.fingard.db.JDBCHelper;
import com.fingard.dsp.bank.directbank.bankInterface.IElecBillQuery;
import com.fingard.dsp.bank.reqrespobj.elecbillquery.*;
import com.fingard.dsp.bank.reqrespobj.elecbillquery.detail.*;
import com.fingard.text.StringHelper;
import com.fingard.util.DateHelper;
import com.fingard.xml.XElement;
import com.fingard.xml.XmlTextReader;
import com.fingard.xml.XmlTextWriter;

/**
 * Created by F on 2018/8/22.
 */
public class SPDB01ElecBill extends SPDB01Base implements IElecBillQuery {

    private static final String SELECTRECEIPT = "SELECT TRANSDATE,REQSEQID,BANKREQSEQID,BUSITYPE FROM REQSEQIDMAPPING WHERE REQSEQID=?;";
    private static final String SELECTCANCEL = "SELECT OUTREQSEQID,TRANSDATE," +
            "BILLNO,BILLAMOUNT,BILLTYPE,ISSDATE,DUEDATE,TRANSFLAG," +
            "DRAWERNAME,DRAWERACTNO,DRAWERBANKCODE,DRAWERBANKNAME," +
            "ACCEPTORNAME,ACCEPTORACTNO,ACCEPTORBANKCODE,ACCEPTORBANKNAME," +
            "RECEIVERNAME,RECEIVERACTNO,RECEIVERBANKCODE,RECEIVERBANKNAME FROM CANCELOPERATIONS " +
            "WHERE BANKCODE =? and BUSITYPE=? and ISFINISHED =1 and ISCANCEL =1";
    //    private static final String UPDATECANCEL = "UPDATE CANCELOPERATIONS SET ISFINISHED =? WHERE OUTREQSEQID=? AND BILLNO =? and ISFINISHED=? AND ISCANCEL=1;";
    private static final String DELETECANCEL = "DELETE FROM CANCELOPERATIONS  WHERE OUTREQSEQID=? AND BILLNO =? and ISFINISHED=? AND ISCANCEL=1;";

    @Override
    public RetAtsB001OperBillQry D_OperBill_Query_Req(ReqB001OperBillQry query) throws Exception {
        RetAtsB001OperBillQry retAts = new RetAtsB001OperBillQry(query.reqHeader);
        retAts.respCode ="0";
        String respCode="";
        String respInfo ="";
        retAts.writeBefore();
        try{
            while (query.readRecord()) {
                if("1".equals(query.detail.queryType)&&"14".equals(query.detail.busiType)){
                    queryBillByEE25(query, retAts);//待签收票据查询
                } else if ("1".equals(query.detail.queryType)) {
                    queryBillByEE23(query, retAts);
                } else if ("2".equals(query.detail.queryType)) {
                    if("12".equals(query.detail.busiType)) {
                        queryPaySignBillByEE25(query,retAts);
                    }else{
                        queryBillByEE25(query, retAts);//待签收票据查询
                    }
                } else if ("3".equals(query.detail.queryType) && "1".equals(query.detail.busiType)){
                    queryBillByEE23(query, retAts);
                }else if ("3".equals(query.detail.queryType)){
                    queryBillByLocalDB(query,retAts);
                }else {
                    throw new Exception("查询类型不明：" + query.detail.queryType);
                }
            }
        }catch (Exception ex ){
            ex.printStackTrace();
            respCode ="-1";
            respInfo = ex.getMessage();
        }
        if("-1".equals(respCode)){
            retAts = new RetAtsB001OperBillQry(query.reqHeader);
            retAts.writeStart();
            retAts.writeBatRespCode(respCode);
            retAts.writeRespInfo(respInfo);
        }
        retAts.writeEnd();
        return retAts;
    }
    //查回可以撤销的记录
    private void queryBillByLocalDB(ReqB001OperBillQry query, RetAtsB001OperBillQry retAts) throws Exception {
        try{
            Connection conn = FGBiz.getLocalDbConn();
            String busiType ;
            switch (Integer.valueOf(query.detail.busiType)) {
                case 2:busiType = "EE03";break;//承兑撤回
                case 3:busiType = "EE04";break;//提示收票撤回
                case 4:busiType = "EE12";break;//背书撤回
                case 5:busiType = "EE09";break;//质押撤回
                case 6:busiType = "EE10";break;//质押解除撤回
                case 10:busiType = "EE07";break;//贴现撤回
                case 12:busiType = "EE14";break;//提示付款撤回
                case 13:busiType = "EE15";break;//追索通知
                case 14:busiType = "EE16";break;//同意清偿
                default:
                    throw  new Exception("位置的业务类型:" + query.detail.busiType);
            }
            List<Map<String,Object>> list = JDBCHelper.execQuery(conn,SELECTCANCEL, new Object[]{"SPDB01",busiType});
            for(Map<String,Object> map:list){
                RetAtsB001OperBillQryDetail detail = new RetAtsB001OperBillQryDetail();
                Object BILLTYPE = map.get("BILLTYPE");
                if(!query.detail.billType.equals(BILLTYPE.toString())){
                    continue;
                }
                detail.billType = (BILLTYPE==null)?"":("1".equals(BILLTYPE.toString())?"EM001":"EM002");
                Object billNo = map.get("BILLNO");
                detail.billNo = (billNo==null)?"":billNo.toString();
                Object billAmt = map.get("BILLAMOUNT");
                detail.billAmt = (billAmt==null)?"":billAmt.toString();
                Object ISSDATE = map.get("ISSDATE");
                detail.issDate = (ISSDATE==null)?"":ISSDATE.toString();
                Object DUEDATE = map.get("DUEDATE");
                detail.dueDate = (DUEDATE==null)?"":DUEDATE.toString();
                Object TRANSFLAG = map.get("TRANSFLAG");
                detail.transFlag = (TRANSFLAG==null)?"":TRANSFLAG.toString();
//            Object applyDate = map.get("TRANSDATE");
//            detail.applyDate = (applyDate==null)?"":applyDate.toString();
//            DRAWERACTNO,DRAWERBANKCODE,DRAWERBANKNAME,
                Object DRAWERACTNO = map.get("DRAWERACTNO");
                detail.drawAct = (DRAWERACTNO==null)?"":DRAWERACTNO.toString();
                Object DRAWERNAME = map.get("DRAWERNAME");
                detail.drawName = (DRAWERNAME==null)?"":DRAWERNAME.toString();
                Object DRAWERBANKNAME = map.get("DRAWERBANKNAME");
                detail.drawBnkName = (DRAWERBANKNAME==null)?"":DRAWERBANKNAME.toString();
                Object DRAWERBANKCODE = map.get("DRAWERBANKCODE");
                detail.drawBnkCode = (DRAWERBANKCODE==null)?"":DRAWERBANKCODE.toString();
//            "ACCEPTORNAME,ACCEPTORACTNO,ACCEPTORBANKCODE,ACCEPTORBANKNAME,"
                Object ACCEPTORNAME = map.get("ACCEPTORNAME");
                detail.accpName = (ACCEPTORNAME==null)?"":ACCEPTORNAME.toString();
                Object ACCEPTORACTNO = map.get("ACCEPTORACTNO");
                detail.accpAct = (ACCEPTORACTNO==null)?"":ACCEPTORACTNO.toString();
                Object ACCEPTORBANKCODE = map.get("ACCEPTORBANKCODE");
                detail.accpBnkCode = (ACCEPTORBANKCODE==null)?"":ACCEPTORBANKCODE.toString();
                Object ACCEPTORBANKNAME = map.get("ACCEPTORBANKNAME");
                detail.accpBnkName= (ACCEPTORBANKNAME==null)?"":ACCEPTORBANKNAME.toString();
//            "RECEIVERNAME,RECEIVERACTNO,RECEIVERBANKCODE,RECEIVERBANKNAME
                Object RECEIVERNAME = map.get("RECEIVERNAME");
                detail.payeeName = (RECEIVERNAME==null)?"":RECEIVERNAME.toString();
                Object RECEIVERACTNO = map.get("RECEIVERACTNO");
                detail.payeeAct = (RECEIVERACTNO==null)?"":RECEIVERACTNO.toString();
                Object RECEIVERBANKCODE = map.get("RECEIVERBANKCODE");
                detail.payeeBnkCode = (RECEIVERBANKCODE==null)?"":RECEIVERBANKCODE.toString();
                Object RECEIVERBANKNAME = map.get("RECEIVERBANKNAME");
                detail.payeeBnkName = (RECEIVERBANKNAME==null)?"":RECEIVERBANKNAME.toString();
                Object busiNo = map.get("OUTREQSEQID");
                detail.busiNo = (busiNo==null)?"":busiNo.toString();
                retAts.writeDetail(detail);
            }
        }catch (Exception ex){
            ex.printStackTrace();
            throw ex;
        }

    }

    private void queryBillByEE23(ReqB001OperBillQry query, RetAtsB001OperBillQry retAts) throws Exception {
        int numStart = 1;
        int totalNum = -1;
        while (numStart <= totalNum || totalNum == -1) {
            XmlTextWriter xmlTextWriter = new XmlTextWriter();
            SPDB01Header header = new SPDB01Header();
            header.transCode = "EE23";
//                <body>
            xmlTextWriter.writeStartElement("body");
//                <transMasterID></transMasterID>
            xmlTextWriter.writeElementString("transMasterID",getTransMasterID(query.detail.actNum));
//                <eBillBusessType></eBillBusessType>
            String eBillBusessType="";
            if("1".equals(query.detail.queryType)){
                switch (Integer.valueOf(query.detail.busiType)){
                    case 1:throw new Exception("银行不支持出票的可操作票据查询");//出票
                    case 2:eBillBusessType = "02";break;//承兑
                    case 3:eBillBusessType = "03";break;//提示收票
                    case 4:eBillBusessType = "05";break;//背书转让
                    case 5:eBillBusessType = "15";break;//质押
                    case 6:eBillBusessType = "16";break;//质押解除
                    case 10:eBillBusessType = "06";break;//贴现
                    case 12:if("1".equals(query.detail.overdueFlag)){
                        eBillBusessType = "17";
                    }else{
                        eBillBusessType = "18";
                    }break;//提示付款
                    case 13:eBillBusessType = "19";break;//追索
                    case 14:throw new Exception("银行不支持清偿的可操作票据查询");//同意清偿
                    default:throw new Exception("未知的申请操作类型");
                }
            }else if("3".equals(query.detail.queryType)){
                switch (Integer.valueOf(query.detail.busiType)){
                    case 1:eBillBusessType = "04";break;//撤票
                    default:throw new Exception("银行不支持该撤销的可操作票据查询");
                }
            }
            xmlTextWriter.writeElementString("eBillBusessType",eBillBusessType );
//                <eBillType></eBillType>
            String billType;
            if("1".equals(query.detail.billType)){
                billType = "AC01";
            }else {
                billType = "AC02";
            }
            xmlTextWriter.writeElementString("eBillType",billType );
//                <beginDate></beginDate>
            xmlTextWriter.writeElementString("beginDate",query.detail.dueDateUp );//票据到期日开始日期
//                <endDate></endDate>
            xmlTextWriter.writeElementString("endDate",query.detail.dueDateDown );//票据到期日结束日期
            if(StringHelper.hasAnyChar(query.detail.billAmtDown)) {
//                <eBillAmount></eBillAmount>
                xmlTextWriter.writeElementString("eBillAmount", String.format("%13s", query.detail.billAmtDown));//票面金额最小值(13)
            }
            if(StringHelper.hasAnyChar(query.detail.billNo)) {
//                <billNo></billNo>
                xmlTextWriter.writeElementString("billNo", query.detail.billNo);//票据号码
            }
//                <beginNumber></beginNumber>
            xmlTextWriter.writeElementString("beginNumber", String.format("%4s",numStart));//起始记录数(4)
//                <queryNumber></queryNumber>
            xmlTextWriter.writeElementString("queryNumber", String.format("%4s",20));//查询记录数(4)
//                <recourseType></recourseType>
            if(StringHelper.hasAnyChar(query.detail.recourseType)) {
                xmlTextWriter.writeElementString("recourseType","1".endsWith(query.detail.recourseType)?"RT00":"RT01" );//追索类型(4)
            }
            if(StringHelper.hasAnyChar(query.detail.billAmtUp)) {
//                <eMaxAmount></eMaxAmount>
                xmlTextWriter.writeElementString("eMaxAmount",String.format("%13s",query.detail.billAmtUp) );//票据金额最大值(13)
            }
            xmlTextWriter.writeElementString("applyAcct",query.detail.actNum );
//                </body>
            xmlTextWriter.writeEndDocument();
            String[] result = sendToBank(xmlTextWriter.toXmlString(), header);
            if (result[0].length() == 0) {
                StringBuilder tmpsbMsg = new StringBuilder();
                XmlTextReader tmpbkReader = loadBankRespXmlReader(result[1], tmpsbMsg);
                if (tmpbkReader != null) {
                    String returnCode = tmpbkReader.getFirstText("/packet/head/returnCode");
                    if(StringHelper.hasAnyChar(returnCode)&&"AAAAAAA".equals(returnCode)){
                        if(totalNum==-1){
                            totalNum = Integer.valueOf(tmpbkReader.getFirstText("/packet/body/totalNumber"));
                        }
                        while (tmpbkReader.read("/packet/body/lists/list")) {
                            numStart++;
                            RetAtsB001OperBillQryDetail detail = new RetAtsB001OperBillQryDetail();
                            detail.drawAct = tmpbkReader.readedXElement.getSingleText("eDrawerAcctNo").trim();
//                                        if("02".equals(eBillBusessType)||"03".equals(eBillBusessType)||"04".equals(eBillBusessType)) {
//                                            if (!query.detail.actNum.equals(detail.drawAct)) {
//                                                continue;
//                                            }
//                                        }
                            detail.billNo = tmpbkReader.readedXElement.getSingleText("billNo").trim();
                            String issDate = tmpbkReader.readedXElement.getSingleText("voteDate").trim();
                            detail.issDate = DateHelper.convertD8toD10(issDate);
                            String dueDate = tmpbkReader.readedXElement.getSingleText("expiryDate").trim();
                            detail.dueDate = DateHelper.convertD8toD10(dueDate);
                            detail.billAmt = tmpbkReader.readedXElement.getSingleText("eBillAmount").trim();
                            String eBillType = tmpbkReader.readedXElement.getSingleText("eBillType").trim();
                            detail.billType = "AC01".equals(eBillType) ? "EM001" : "EM002";
                            String canTransferFlag = tmpbkReader.readedXElement.getSingleText("canTransferFlag").trim();
                            detail.transFlag = "EM00".equals(canTransferFlag) ? "1" : "0";
                            detail.drawName = tmpbkReader.readedXElement.getSingleText("eDrawerName").trim();
                            detail.drawBnkCode = tmpbkReader.readedXElement.getSingleText("eDrawerBankNo").trim();
                            detail.payeeName = tmpbkReader.readedXElement.getSingleText("ePayeeAcctName").trim();
                            detail.payeeAct = tmpbkReader.readedXElement.getSingleText("ePayeeAcctNo").trim();
                            detail.payeeBnkCode = tmpbkReader.readedXElement.getSingleText("ePayeeBankNo").trim();
                            detail.billStatus = tmpbkReader.readedXElement.getSingleText("eBillStatus").trim();
                            detail.accpName = tmpbkReader.readedXElement.getSingleText("acceptorName").trim();
                            detail.accpBnkCode = tmpbkReader.readedXElement.getSingleText("acceptorBankNo").trim();
                            detail.overDueFlag = query.detail.overdueFlag;
                            retAts.writeDetail(detail);
                        }
                    }else {
                        throw new Exception(tmpbkReader.getFirstText("/packet/body/returnMsg"));
                    }
                } else {
                    throw new Exception(tmpsbMsg.toString());
                }
            } else {
                throw new Exception(result[1]);
            }

        }
    }

    private void queryBillByEE25(ReqB001OperBillQry query, RetAtsB001OperBillQry retAts)throws Exception{
        int numStart = 1;
        int totalNum = -1;
        while (numStart <= totalNum || totalNum == -1) {
            XmlTextWriter xmlTextWriter = new XmlTextWriter();
            SPDB01Header header = new SPDB01Header();
            header.transCode = "EE25";
//                <body>
            xmlTextWriter.writeStartElement("body");
//                    transMasterID	交易客户号	FixNumber(10)		备用字段
            xmlTextWriter.writeElementString("transMasterID",getTransMasterID(query.detail.actNum));
//                    eBillBusessType	查询类别	FixString(2)	Y
            String eBillBusessType;
            switch (Integer.valueOf(query.detail.busiType)){
                case 2:eBillBusessType = "02";break;//承兑待签收
                case 3:eBillBusessType = "03";break;//收票待签收
                case 4:eBillBusessType = "05";break;//背书待签收
                case 11:eBillBusessType = "07";break;//回购式贴现赎回待签收
                case 6:eBillBusessType = "16";break;//质押解除待签收
                case 5:eBillBusessType = "15";break;//质押解除待签收
                case 14:if("2".equals(query.detail.queryType)){
                    eBillBusessType = "20";
                } else{
                    eBillBusessType = "19";
                }break;//追索清偿
                default:throw new Exception("业务类型未知："+query.detail.busiType);
            }
            xmlTextWriter.writeElementString("eBillBusessType",eBillBusessType );
//                    eBillType	票据种类	FixString(4)	N	AC01银承 AC02商承
            String billType;
            if("1".equals(query.detail.billType)){
                billType = "AC01";
            }else {
                billType = "AC02";
            }
            xmlTextWriter.writeElementString("eBillType",billType );
//                    beginDate	对方行业务申请开始日期	FixString(8)	Y
            xmlTextWriter.writeElementString("beginDate",query.detail.dueDateUp );//票据到期日开始日期
//                    endDate	对方行业务申请结束日期	FixString(8)	Y
            xmlTextWriter.writeElementString("endDate",query.detail.dueDateDown );//票据到期日结束日期
//                    beginNumber	起始记录数	FixNumber(4)	Y	最小为1
            xmlTextWriter.writeElementString("beginNumber", String.format("%4s",numStart));//起始记录数(4)
//                <queryNumber></queryNumber>
            xmlTextWriter.writeElementString("queryNumber", String.format("%4s",10));//查询记录数(4)
            xmlTextWriter.writeElementString("signerAcct",query.detail.actNum );//查询记录数(4)
            xmlTextWriter.writeEndDocument();
            String[] result = sendToBank(xmlTextWriter.toXmlString(), header);
            if (result[0].length() == 0) {
                StringBuilder tmpsbMsg = new StringBuilder();
                XmlTextReader tmpbkReader = loadBankRespXmlReader(result[1], tmpsbMsg);
                if (tmpbkReader != null) {
                    String returnCode = tmpbkReader.getFirstText("/packet/head/returnCode");
                    if(StringHelper.hasAnyChar(returnCode)&&"AAAAAAA".equals(returnCode)){
                        if(totalNum==-1){
                            totalNum = Integer.valueOf(tmpbkReader.getFirstText("/packet/body/totalNumber"));
                        }
                        while (tmpbkReader.read("/packet/body/lists/list")) {
                            RetAtsB001OperBillQryDetail detail = new RetAtsB001OperBillQryDetail();
//                                    transJnlNo	业务ID	FixString(20)		业务流水号，签收票据时使用
                            detail.busiNo = tmpbkReader.readedXElement.getSingleText("transJnlNo").trim();
//                                    billNo	电子票据序列号	FixString(30)
                            detail.billNo =tmpbkReader.readedXElement.getSingleText("billNo").trim();
//                                    voteDate	出票日	FixString(8)
                            String issDate =tmpbkReader.readedXElement.getSingleText("voteDate").trim();
                            detail.issDate = DateHelper.convertD8toD10(issDate);
//                                    expiryDate	到期日	FixString(8)
                            String dueDate =tmpbkReader.readedXElement.getSingleText("expiryDate").trim();
                            detail.dueDate =DateHelper.convertD8toD10(dueDate);
//                                    eBillType	票据类型	FixString(4)		AC01银承 AC02商承
                            String eBillType = tmpbkReader.readedXElement.getSingleText("eBillType").trim();
                            detail.billType="AC01".equals(eBillType)?"EM001":"EM002";
//                                    eBillAmount	票面金额	FixNumber(13,2)
                            detail.billAmt =tmpbkReader.readedXElement.getSingleText("eBillAmount").trim();
//                                    canTransferFlag	转让标记	FixString(4)		EM00可再转让 EM01不得转让
                            String canTransferFlag =tmpbkReader.readedXElement.getSingleText("canTransferFlag").trim();
                            detail.transFlag ="EM00".equals(canTransferFlag)?"1":"0" ;
//                                    unconditionalPayConsign	到期无条件支付委托	FixString(4)		只能填写CC00
                            String unconditionalPayConsign = tmpbkReader.readedXElement.getSingleText("unconditionalPayConsign").trim();
                            if("CC00".equals(unconditionalPayConsign)){
                                detail.mustPay = "1";
                            }
//                                    eBillStatus	票据状态	FixString(6)		见12.16
                            detail.billStatus=tmpbkReader.readedXElement.getSingleText("eBillStatus").trim();
//                                    applyDate	申请日期	FixString(8)
                            detail.applyDate =DateHelper.convertD8toD10(tmpbkReader.readedXElement.getSingleText("applyDate").trim());
//                                    applyName	申请人名称	FixString(62)
                            detail.applyName = tmpbkReader.readedXElement.getSingleText("applyName").trim();
//                                    applyAcctNo	申请人账号	FixString(32)
                            detail.applyAct = tmpbkReader.readedXElement.getSingleText("applyAcctNo").trim();
//                                    applyOrgId	申请人组织机构代码	FixString(20)
                            detail.applyCode = tmpbkReader.readedXElement.getSingleText("applyOrgId").trim();
//                                    applyBankNo	申请人行号	FixString(12)
                            detail.applyBnkCode = tmpbkReader.readedXElement.getSingleText("applyBankNo").trim();
//                                    ePayeeAcctName	接收人名称	FixString(62)
                            detail.receName =tmpbkReader.readedXElement.getSingleText("ePayeeAcctName").trim();
//                                    ePayeeAcctNo	接收人账号	FixString(20)
                            detail.receAct =tmpbkReader.readedXElement.getSingleText("ePayeeAcctNo").trim();
//                                    ePayeeOrgId	接收人组织机构代码	FixString(32)
                            detail.receCode =tmpbkReader.readedXElement.getSingleText("ePayeeOrgId").trim();
//                                    ePayeeBankNo	接收人行号	FixString(12)
                            detail.receBnkCode =tmpbkReader.readedXElement.getSingleText("ePayeeBankNo").trim();
//                                    discountType	贴现类型	FixString(4)		RM00买断式
//                                            RM01回购式
                            String discountType = tmpbkReader.readedXElement.getSingleText("discountType").trim();
                            if("RM00".equals(discountType)){
                                detail.discType ="1";
                            }else if("RM01".equals(discountType)){
                                detail.discType ="2";
                            }
//                                    discountRate	贴现利率	FixNumber(9,7)
//                                    detail.discRate = tmpbkReader.readedXElement.getSingleText("discountRate").trim();
//                                    amount	实付金额	FixNumber(13,2)
//                                    redemptionOpenDate	回购起始日	FixString(8)		 回购式贴现时返回
                            String redemptionOpenDate =tmpbkReader.readedXElement.getSingleText("redemptionOpenDate").trim();
                            if(StringHelper.hasAnyChar(redemptionOpenDate)&&!"00000000".equals(redemptionOpenDate)){
                                detail.repOpenDate = DateHelper.convertD8toD10(redemptionOpenDate);
                            }
//                                    redemptionEndDate	回购到期日	FixString(8)		 回购式贴现时返回
                            String redemptionEndDate =tmpbkReader.readedXElement.getSingleText("redemptionEndDate").trim();
                            if(StringHelper.hasAnyChar(redemptionEndDate)&&!"00000000".equals(redemptionOpenDate)) {
                                detail.repDueDate = DateHelper.convertD8toD10(tmpbkReader.readedXElement.getSingleText("redemptionEndDate").trim());
                            }
//                                    redemptionRate	回购利率	FixNumber(9,7)		 回购式贴现时返回
//                                    detail.repRate =tmpbkReader.readedXElement.getSingleText("redemptionRate").trim();
//                                    redemptionAmount	回购实付金额	FixNumber(13,2)		 回购式贴现时返回
//                                    liquidationType	清算方式	FixString(4)		SM00线上清算 SM01线下清算
                            String liquidationType = tmpbkReader.readedXElement.getSingleText("liquidationType").trim();
                            if("SM00".equals(liquidationType)){
                                detail.payType = "1";
                            }else if("SM01".equals("liquidationType")){
                                detail.payType = "2";
                            }
//                                    noPayReason	拒付理由	FixString(2)		01、与自己有直接债权债务关系的持票人未履行约定义务；
//                                    02、持票人以欺诈、偷盗或者胁迫等手段取得票据；
//                                    03、持票人明知有欺诈、偷盗或者胁迫等情形，出于恶意取得票据；
//                                    04、持票人明知债务人与出票人或者持票人的前手之间存在抗辩事由而取得票据；
//                                    05、持票人因重大过失取得不符合《票据法》规定的票据；
//                                    06、超过提示付款期；
//                                    07、被法院冻结或收到法院止付通知书；
//                                    08、票据未到期；
//                                    09、商业承兑汇票承兑人账户余额不足。
//                                    10、其他（必须注明）。
//                                    noPayRemark	拒付备注	VarString(256)		拒付代码为10时，填写
//                                    recourseType	追索类型	FixString(4)		RT00拒付追索
//                                            RT01非拒付追索
                            if("19".equals(eBillBusessType)) {
                                String recourseType =tmpbkReader.readedXElement.getSingleText("recourseType").trim();
                                if("RT00".equals(recourseType)){
                                    detail.recourseType ="1";
                                }else if("RT01".equals(recourseType)){
                                    detail.recourseType ="2";
                                }
//                                    recourseApplyAmount	追索金额	FixNumber(13,2)
                                detail.recourseAmt = tmpbkReader.readedXElement.getSingleText("recourseApplyAmount").trim();
                            }
                            retAts.writeDetail(detail);
                            numStart++;
                        }
                    }else {
                        throw  new Exception(tmpbkReader.getFirstText("/packet/body/returnMsg"));
                    }
                } else {
                    throw  new Exception(tmpsbMsg.toString());
                }

            } else {
                throw new Exception(result[1]);
            }
        }
    }
    private void queryPaySignBillByEE25(ReqB001OperBillQry query, RetAtsB001OperBillQry retAts)throws Exception{
        for(int overdueFlagInt=1;overdueFlagInt<3;overdueFlagInt++) {
            int numStart = 1;
            int totalNum = -1;
            while (numStart <= totalNum || totalNum == -1) {
                XmlTextWriter xmlTextWriter = new XmlTextWriter();
                SPDB01Header header = new SPDB01Header();
                header.transCode = "EE25";
                xmlTextWriter.writeStartElement("body");
                xmlTextWriter.writeElementString("transMasterID", getTransMasterID(query.detail.actNum));
                String eBillBusessType;
                if(overdueFlagInt==1){
                    eBillBusessType = "17";
                } else {
                    eBillBusessType = "18";
                }
                xmlTextWriter.writeElementString("eBillBusessType", eBillBusessType);
                String billType;
                if ("1".equals(query.detail.billType)) {
                    billType = "AC01";
                } else {
                    billType = "AC02";
                }
                xmlTextWriter.writeElementString("eBillType", billType);
                xmlTextWriter.writeElementString("beginDate", query.detail.dueDateUp);//票据到期日开始日期
                xmlTextWriter.writeElementString("endDate", query.detail.dueDateDown);//票据到期日结束日期
                xmlTextWriter.writeElementString("beginNumber", String.format("%4s", numStart));//起始记录数(4)
                xmlTextWriter.writeElementString("queryNumber", String.format("%4s", 10));//查询记录数(4)
                xmlTextWriter.writeElementString("signerAcct",query.detail.actNum );//查询记录数(4)
                xmlTextWriter.writeEndDocument();
                String[] result = sendToBank(xmlTextWriter.toXmlString(), header);
                if (result[0].length() == 0) {
                    StringBuilder tmpsbMsg = new StringBuilder();
                    XmlTextReader tmpbkReader = loadBankRespXmlReader(result[1], tmpsbMsg);
                    if (tmpbkReader != null) {
                        String returnCode = tmpbkReader.getFirstText("/packet/head/returnCode");
                        if (StringHelper.hasAnyChar(returnCode) && "AAAAAAA".equals(returnCode)) {
                            if (totalNum == -1) {
                                totalNum = Integer.valueOf(tmpbkReader.getFirstText("/packet/body/totalNumber"));
                            }
                            while (tmpbkReader.read("/packet/body/lists/list")) {
                                RetAtsB001OperBillQryDetail detail = new RetAtsB001OperBillQryDetail();
                                detail.busiNo = tmpbkReader.readedXElement.getSingleText("transJnlNo").trim();
                                detail.billNo = tmpbkReader.readedXElement.getSingleText("billNo").trim();
                                String issDate = tmpbkReader.readedXElement.getSingleText("voteDate").trim();
                                detail.issDate = DateHelper.convertD8toD10(issDate);
                                String dueDate = tmpbkReader.readedXElement.getSingleText("expiryDate").trim();
                                detail.dueDate = DateHelper.convertD8toD10(dueDate);
                                String eBillType = tmpbkReader.readedXElement.getSingleText("eBillType").trim();
                                detail.billType = "AC01".equals(eBillType) ? "EM001" : "EM002";
                                detail.billAmt = tmpbkReader.readedXElement.getSingleText("eBillAmount").trim();
                                String canTransferFlag = tmpbkReader.readedXElement.getSingleText("canTransferFlag").trim();
                                detail.transFlag = "EM00".equals(canTransferFlag) ? "1" : "0";
                                String unconditionalPayConsign = tmpbkReader.readedXElement.getSingleText("unconditionalPayConsign").trim();
                                if ("CC00".equals(unconditionalPayConsign)) {
                                    detail.mustPay = "1";
                                }
                                detail.billStatus = tmpbkReader.readedXElement.getSingleText("eBillStatus").trim();
                                detail.applyDate = DateHelper.convertD8toD10(tmpbkReader.readedXElement.getSingleText("applyDate").trim());
                                detail.applyName = tmpbkReader.readedXElement.getSingleText("applyName").trim();
                                detail.applyAct = tmpbkReader.readedXElement.getSingleText("applyAcctNo").trim();
                                detail.applyCode = tmpbkReader.readedXElement.getSingleText("applyOrgId").trim();
                                detail.applyBnkCode = tmpbkReader.readedXElement.getSingleText("applyBankNo").trim();
                                detail.receName = tmpbkReader.readedXElement.getSingleText("ePayeeAcctName").trim();
                                detail.receAct = tmpbkReader.readedXElement.getSingleText("ePayeeAcctNo").trim();
                                detail.receCode = tmpbkReader.readedXElement.getSingleText("ePayeeOrgId").trim();
                                detail.receBnkCode = tmpbkReader.readedXElement.getSingleText("ePayeeBankNo").trim();
                                String liquidationType = tmpbkReader.readedXElement.getSingleText("liquidationType").trim();
                                if ("SM00".equals(liquidationType)) {
                                    detail.payType = "1";
                                } else if ("SM01".equals("liquidationType")) {
                                    detail.payType = "2";
                                }
                                detail.overDueRea = tmpbkReader.readedXElement.getSingleText("outDatePayMsg").trim();
                                detail.overDueFlag = overdueFlagInt+"";
                                retAts.writeDetail(detail);
                                numStart++;
                            }
                        } else {
                            throw new Exception(tmpbkReader.getFirstText("/packet/body/returnMsg"));
                        }
                    } else {
                        throw new Exception(tmpsbMsg.toString());
                    }
                } else {
                    throw new Exception(result[1]);
                }
            }
        }
    }


    @Override
    public RetAtsB002BillTransQry D_B002_BillTrans_Query(ReqB002BillTransQry query) throws Exception {

        RetAtsB002BillTransQry retAts = new RetAtsB002BillTransQry(query.reqHeader);
        retAts.respCode ="0";
        retAts.writeBefore();
        String respCode ="";
        String respInfo ="";
        int offset = 0;
        int endset = -1;
        do{
            try {
                XmlTextWriter xmlTextWriter = new XmlTextWriter();
                SPDB01Header header = new SPDB01Header();
                header.transCode = "EE24";
                xmlTextWriter.writeStartElement("body");
//            billNo	电子票号	FixString(30)	Y
                xmlTextWriter.writeElementString("billNo", String.format("%-30s", query.billNo));//电子票号
//            eBillBusessType	查询类别（流转类别）	FixString(2)	Y	01-	提示承兑
                String eBillBusessType = "";
                if("1".equals(query.queryType)){
                    switch (Integer.valueOf(query.busiType)) {
                        case 1:
                            throw new Exception("银行不支持出票的操作明细查询");//出票
                        case 2:
                            eBillBusessType = "01";
                            break;//提示承兑
                        case 3:
                            eBillBusessType = "02";
                            break;//02-	提示收票
                        case 4:
                            eBillBusessType = "03";
                            break;//背书转让
                        case 5:
                            eBillBusessType = "12";
                            break;//质押
                        case 10:
                            eBillBusessType = "04";
                            break;//贴现
                        case 12:
                            eBillBusessType = "14";
                            break;//提示付款
                        case 13:
                            eBillBusessType = "16";
                            break;//追索
                        case 14:
                            throw new Exception("银行不支持同意清偿的操作明细查询");//同意清偿
                        default:
                            throw new Exception("未知的申请操作类型：" + query.busiType);
                    }
                }else if("2".equals(query.queryType)){
                    switch (Integer.valueOf(query.busiType)) {
                        case 2:
                            throw new Exception("银行不支持承兑签收的操作明细查询");//承兑签收
                        case 3:
                            throw new Exception("银行不支持收票签收的操作明细查询");//收票签收
                        case 4:
                            throw new Exception("银行不支持背书转让签收的操作明细查询");//背书转让签收
                        case 6:
                            throw new Exception("银行不支持质押解除签收签收的操作明细查询");//质解签收
                        case 11:
                            throw new Exception("银行不支持回购式贴现赎回签收的操作明细查询");//回购式贴现赎回签收
                        case 14:
                            throw new Exception("银行不支持同意清偿签收的操作明细查询");//同意清偿签收
                        default:
                            throw new Exception("未知的签收操作类型：" + query.busiType);
                    }
                }else if("3".equals(query.queryType)){
                    switch (Integer.valueOf(query.busiType)) {
                        case 1:
                            throw new Exception("银行不支持撤票的操作明细查询");//撤票
                        case 2:
                            throw new Exception("银行不支持承兑撤回的操作明细查询");//承兑撤回
                        case 3:
                            throw new Exception("银行不支持收票撤回的操作明细查询");//收票撤回
                        case 4:
                            throw new Exception("银行不支持背书转让撤回的操作明细查询");//背书转让撤回
                        case 5:
                            throw new Exception("银行不支持质押撤回的操作明细查询");//质押撤回
                        case 10:
                            throw new Exception("银行不支持贴现撤回的操作明细查询");//贴现撤回
                        case 12:
                            throw new Exception("银行不支持提示付款撤回的操作明细查询");//提示付款撤回
                        case 13:
                            throw new Exception("银行不支持追索通知撤回的操作明细查询");//追索通知撤回
                        case 14:
                            throw new Exception("银行不支持同意清偿撤回的操作明细查询");//同意清偿撤回
                        default:
                            throw new Exception("未知的撤回操作类型：" + query.busiType);
                    }
                }
//
                xmlTextWriter.writeElementString("eBillBusessType", eBillBusessType);

//            tra"nsJnlNo	业务流水号	FixString(10)	N	业务流水查询中发起票据流转信息查询时需要提供业务流水号；其他情况无需提供。
                xmlTextWriter.writeElementString("transJnlNo", String.format("%-10s", query.busiNo));//业务流水号(10)

//            beginNumber	起始记录数	FixNumber(4)	Y	　最小为1
                xmlTextWriter.writeElementString("beginNumber", String.format("%4s", "" + offset));//起始记录数(4)

//            queryNumber	查询记录数	FixNumber(4)	Y	　最大为20
                xmlTextWriter.writeElementString("queryNumber", String.format("%4s", "" + 10));//查询记录数(4)
                String[] result = sendToBank(xmlTextWriter.toXmlString(), header);
                if (result[0].length() == 0) {
                    StringBuilder tmpsbMsg = new StringBuilder();
                    XmlTextReader tmpbkReader = loadBankRespXmlReader(result[1], tmpsbMsg);
                    if (tmpbkReader != null) {
                        String returnCode = tmpbkReader.getFirstText("/packet/head/returnCode");
                        if (StringHelper.hasAnyChar(returnCode) && "AAAAAAA".equals(returnCode)) {
                            RetAtsB002BillTransQryDetail detail = new RetAtsB002BillTransQryDetail();
                            if (endset == -1) {
                                endset = Integer.valueOf("/packet/body/totalNumber");
                            }
                            if (tmpbkReader.read("/packet/body/lists/list")) {
                                offset++;
                                detail.billNo = tmpbkReader.readedXElement.getSingleText("billNo").trim();//电子票据序列号
//                            signDate	签收日期	FixString(8)
                                String signDate = DateHelper.convertD8toD10(tmpbkReader.readedXElement.getSingleText("applyDate").trim());
                                detail.applyDate = signDate;//申请日期
                                detail.applyName = tmpbkReader.readedXElement.getSingleText("applyName").trim();//申请人名称
                                detail.applyAct = tmpbkReader.readedXElement.getSingleText("applyAcctNo").trim();//申请人账号
                                detail.applyCode = tmpbkReader.readedXElement.getSingleText("applyOrgId").trim();//申请人组织机构代码
                                detail.applyBnkCode = tmpbkReader.readedXElement.getSingleText("applyBankNo").trim();//申请人行号
                                detail.receName = tmpbkReader.readedXElement.getSingleText("ePayeeAcctName").trim();//接收人名称
                                detail.receAct = tmpbkReader.readedXElement.getSingleText("ePayeeAcctNo").trim();//接收人账号
                                detail.receCode = tmpbkReader.readedXElement.getSingleText("ePayeeOrgId").trim();//接收人组织机构代码
                                detail.receBnkCode = tmpbkReader.readedXElement.getSingleText("ePayeeBankNo").trim();//接收人行号
                                String discountType = tmpbkReader.readedXElement.getSingleText("discountType").trim();
                                if ("RM00".equals(discountType)) {
                                    detail.discType = "1";//贴现类型
                                } else if ("RM01".equals(discountType)) {
                                    detail.discType = "2";
                                }
                                detail.discRate = tmpbkReader.readedXElement.getSingleText("discountRate").trim();//贴现利率
                                detail.discAmt = tmpbkReader.readedXElement.getSingleText("amount").trim();//实付金额
                                detail.repOpenDate = tmpbkReader.readedXElement.getSingleText("redemptionOpenDate").trim();
                                detail.repDueDate = tmpbkReader.readedXElement.getSingleText("redemptionEndDate").trim();
                                detail.repRate = tmpbkReader.readedXElement.getSingleText("redemptionRate").trim();
                                detail.repAmt = tmpbkReader.readedXElement.getSingleText("redemptionAmount").trim();
                                String liquidationType = tmpbkReader.readedXElement.getSingleText("liquidationType").trim();
                                if ("SM00".equals(liquidationType)) {
                                    detail.payType = "1";//清算标记
                                } else if ("SM01".equals(liquidationType)) {
                                    detail.payType = "2";
                                }
                                String bondType = tmpbkReader.readedXElement.getSingleText("bondType").trim();
                                if ("GT00".equals(bondType)) {
                                    detail.guarType = "1";
                                } else if ("GT01".equals(bondType)) {
                                    detail.guarType = "2";
                                } else if ("GT02".equals(bondType)) {
                                    detail.guarType = "3";
                                }
                                String noPayReason = tmpbkReader.readedXElement.getSingleText("noPayReason").trim();
                                if (StringHelper.hasAnyChar(noPayReason)) {
                                    int i = Integer.valueOf(noPayReason.substring(3));
                                    if (i == 9) {
                                        i = 99;
                                    } else {
                                        i++;
                                    }
                                    detail.unPayCode = "" + i;
                                }
                                String noPayRemark = tmpbkReader.readedXElement.getSingleText("noPayRemark").trim();//拒付备注
                                if (StringHelper.hasAnyChar(noPayReason)) {
                                    detail.memo = noPayRemark;
                                }

                                String recourseType = tmpbkReader.readedXElement.getSingleText("recourseType").trim();
                                if ("RT00".equals(recourseType)) {
                                    detail.recourseType = "1";
                                } else if ("RT01".equals(recourseType)) {
                                    detail.recourseType = "2";
                                }
                                detail.recourseAmt = tmpbkReader.readedXElement.getSingleText("recourseApplyAmount").trim();
                                detail.contractNo = tmpbkReader.readedXElement.getSingleText("bargainNo").trim();//贸易合同号
                                detail.invoiceNo = tmpbkReader.readedXElement.getSingleText("invoiceNo").trim();//发票号码
                                detail.guarAddr = tmpbkReader.readedXElement.getSingleText("acceptorAddr").trim();//保证人地址
                                retAts.writeDetail(detail);
                            }
                        } else {
                            respCode = "-1";
                            respInfo = tmpbkReader.getFirstText("/packet/body/returnMsg");
                        }
                    } else {
                        respCode = "-1";
                        respInfo = tmpsbMsg.toString();
                    }
                } else {
                    respCode = "-1";
                    respInfo = result[1];
                }
            } catch (Exception e) {
                respCode = "-1";
                respInfo = e.getMessage();
                e.printStackTrace();
            }
            if("-1".equals(respCode)){
                break;
            }
        }while (offset<endset);
        if("-1".equals(respCode)){
            retAts = new RetAtsB002BillTransQry(query.reqHeader);
            retAts.respCode ="-1";
            retAts.respInfo = respInfo;
            retAts.writeBefore();
        }
        retAts.writeAfter();
        return retAts;
    }

    @Override
    public RetAtsB004BillFrontQry D_B004_BillFront_Query(ReqB004BillFrontQry query) throws Exception {
        RetAtsB004BillFrontQry retAts = new RetAtsB004BillFrontQry(query.reqHeader);
        retAts.writeStart();
        String respCode = "";
        String respInfo ="";
        while (query.readRecord()){
            XmlTextWriter xmlTextWriter = new XmlTextWriter();
            SPDB01Header header = new SPDB01Header();
            header.transCode ="EE22";
            try {
//                <body>
                xmlTextWriter.writeStartElement("body");
//                <billNo></billNo>
                xmlTextWriter.writeElementString("billNo",query.detail.billNo);//票据号码
//                </body>
                xmlTextWriter.writeEndDocument();
                String[] result = sendToBank(xmlTextWriter.toXmlString(),header);
                if(result[0].length()==0){
                    StringBuilder tmpsbMsg = new StringBuilder();
                    XmlTextReader tmpbkReader = loadBankRespXmlReader(result[1],tmpsbMsg);
                    if(tmpbkReader!=null){
                        String returnCode = tmpbkReader.getFirstText("/packet/head/returnCode");
                        if(StringHelper.hasAnyChar(returnCode)&&"AAAAAAA".equals(returnCode)){
                            while (tmpbkReader.read("/packet/body")){
                                retAts.respCode ="0";
                                retAts.billNo = tmpbkReader.readedXElement.getSingleText("billNo").trim();//票据号
                                String eBillType = tmpbkReader.readedXElement.getSingleText("eBillType").trim();//票据类型
                                if("AC01".equals(eBillType)){
                                    retAts.billType = "1";
                                }else if("AC02".equals(eBillType)){
                                    retAts.billType = "2";
                                }
                                retAts.billAmt = tmpbkReader.readedXElement.getSingleText("eBillAmount").trim();//票据金额
                                retAts.issDate =DateHelper.convertD8toD10(tmpbkReader.readedXElement.getSingleText("voteDate").trim());//出票日期
                                retAts.dueDate =DateHelper.convertD8toD10(tmpbkReader.readedXElement.getSingleText("expiryDate").trim());//到期日
                                String canTransferFlag =tmpbkReader.readedXElement.getSingleText("canTransferFlag").trim();//转让标记
                                if("EM00".equals(canTransferFlag)){
                                    retAts.transFlag = "1";
                                }else if("EM01".equals(canTransferFlag)){
                                    retAts.transFlag = "2";
                                }
                                retAts.drawCode =tmpbkReader.readedXElement.getSingleText("eDrawerOrgId").trim();//出票人组织机构代码
                                retAts.drawName = tmpbkReader.readedXElement.getSingleText("eDrawerName").trim();//出票人名称
                                retAts.drawAct =tmpbkReader.readedXElement.getSingleText("eDrawerAcctNo").trim();//出票人账号
                                retAts.drawBnkCode=tmpbkReader.readedXElement.getSingleText("eDrawerBankNo").trim();//出票人开户行行号
                                retAts.drawBnkName =tmpbkReader.readedXElement.getSingleText("drawerBankName").trim();//出票人开户行名称
                                retAts.payeeName =tmpbkReader.readedXElement.getSingleText("ePayeeAcctName").trim();//收款人名称
                                retAts.payeeAct =tmpbkReader.readedXElement.getSingleText("ePayeeAcctNo").trim() ;//收款人账号
                                retAts.payeeBnkCode =tmpbkReader.readedXElement.getSingleText("ePayeeBankNo").trim();//收款人开户行行号
                                retAts.payeeBnkName =tmpbkReader.readedXElement.getSingleText("payeeHostBankName").trim();//收票人开户行名称
                                retAts.accpName =tmpbkReader.readedXElement.getSingleText("acceptorName").trim();//承兑人名称
                                retAts.accpAct =tmpbkReader.readedXElement.getSingleText("acceptorAcctNo").trim();//承兑人账号
                                retAts.accpBnkCode=tmpbkReader.readedXElement.getSingleText("acceptorBankNo").trim();//承兑人开户行行号
                                retAts.accpBnkName=tmpbkReader.readedXElement.getSingleText("acceptBankName").trim();//承兑行名称
                                retAts.billState =tmpbkReader.readedXElement.getSingleText("eBillStatus").trim();//票据状态
                            }
                        }else {
                            respCode = "-1";
                            respInfo = tmpbkReader.getFirstText("/packet/body/returnMsg");
                        }
                    }else {
                        respCode = "-1";
                        respInfo = tmpsbMsg.toString();
                    }
                }else {
                    respCode = "-1";
                    respInfo = result[1];
                }
            }catch (Exception e){
                respCode = "-1";
                respInfo = e.getMessage();
                e.printStackTrace();
            }
        }
        if("-1".equals(respCode)){
            retAts = new RetAtsB004BillFrontQry(query.reqHeader);
            retAts.writeStart();
            retAts.respCode =respCode;
            retAts.respInfo = respInfo;
        }
        retAts.writeRetDetail();
        retAts.writeEnd();
        return retAts;
    }

    @Override
    public RetAtsB005BillBackQry D_B005_BillBack_Query(ReqB005BillBackQry query) throws Exception {
        RetAtsB005BillBackQry retAts = new RetAtsB005BillBackQry(query.reqHeader);
        retAts.writeStart();
        RetAtsB005BillBackQryDetail detail = new RetAtsB005BillBackQryDetail();
        query.readRecord();
        int startNum = 1;
        int tmpNowReadNum = 0;
        int totalNum =0;
        try {
            do {
                XmlTextWriter xmlTextWriter = new XmlTextWriter();
                SPDB01Header header = new SPDB01Header();
                header.transCode = "EE24";
                xmlTextWriter.writeStartElement("body");
                xmlTextWriter.writeElementString("transMasterID",getTransMasterID(query.detail.actNum));
//            billNo	电子票号	FixString(30)	Y
                xmlTextWriter.writeElementString("billNo", query.detail.billNo);
//            eBillBusessType	查询类别（流转类别）	FixString(2)	Y
                xmlTextWriter.writeElementString("eBillBusessType", "99");
//                transJnlNo	业务流水号	FixString(10)	N
                xmlTextWriter.writeElementString("transJnlNo", "");
//                beginNumber	起始记录数	FixNumber(4)	Y
                xmlTextWriter.writeElementString("beginNumber", "" + startNum);
//                queryNumber	查询记录数	FixNumber(4)	Y
                xmlTextWriter.writeElementString("queryNumber", "20");
                xmlTextWriter.writeEndDocument();
                String[] result = sendToBank(xmlTextWriter.toXmlString(), header);
                if (result[0].length() == 0) {
                    StringBuilder tmpsbMsg = new StringBuilder();
                    XmlTextReader tmpbkReader = loadBankRespXmlReader(result[1], tmpsbMsg);
                    if (tmpbkReader != null) {
                        String returnCode = tmpbkReader.getFirstText("/packet/head/returnCode");
                        if (StringHelper.hasAnyChar(returnCode) && "AAAAAAA".equals(returnCode)) {
                            RetAtsB005BillBackQryDetail items = new RetAtsB005BillBackQryDetail();
                            if (totalNum == 0) {
                                totalNum = Integer.valueOf(tmpbkReader.getFirstText("/packet/body/totalNumber"));
                            }
                            while (tmpbkReader.read("/packet/body/lists/list")) {
                                startNum++;
                                tmpNowReadNum++;
                                items.respCode = "0";
//                                eBillBusessType	流转类别	FixString(2)
                                String eBillBusessType = tmpbkReader.readedXElement.getSingleText("eBillBusessType");
                                if ("01".equals(eBillBusessType)) {
                                    items.transCode = "2";
//                                01-	提示承兑 2
                                } else if ("02".equals(eBillBusessType)) {
                                    items.transCode = "3";
//                                02-	提示收票 3
                                } else if ("03".equals(eBillBusessType)) {
                                    items.transCode = "10";
//                                03-	背书 10
                                } else if ("04".equals(eBillBusessType)) {
                                    items.transCode = "11";
//                                04-	贴现 11
                                } else if ("05".equals(eBillBusessType)) {
                                    items.transCode = "12";
//                                05-	回购式贴现赎回 12
                                } else if ("06".equals(eBillBusessType)) {
                                    items.transCode = "13";
//                                06-	转贴现 13
                                } else if ("07".equals(eBillBusessType)) {
                                    items.transCode = "14";
//                                07-	回购式转贴现赎回 14
                                } else if ("08".equals(eBillBusessType)) {
                                    items.transCode = "15";
//                                08-	再贴现 15
                                } else if ("09".equals(eBillBusessType)) {
                                    items.transCode = "16";
//                                09-	回购式再贴现赎回 16
                                } else if ("10".equals(eBillBusessType)) {
                                    items.transCode = "25";
//                                10-	央行卖出商业汇票 25
                                } else if ("11".equals(eBillBusessType)) {
                                    items.transCode = "17";
//                                11-	保证 17
                                } else if ("12".equals(eBillBusessType)) {
                                    items.transCode = "18";
//                                12-	质押 18
                                } else if ("13".equals(eBillBusessType)) {
                                    items.transCode = "19";
//                                13-	质押解除 19
                                } else if ("14".equals(eBillBusessType)) {
                                    items.transCode = "20";
//                                14-	提示付款 20
                                } else if ("15".equals(eBillBusessType)) {
                                    items.transCode = "21";
//                                15-	逾期提示付款 21
                                } else if ("16".equals(eBillBusessType)) {
                                    items.transCode = "22";
//                                16-	追索 2
                                } else {
//                                99- 所有
                                    continue;
                                }
//                                signDate	签收日期	FixString(8)
                                items.respDate = DateHelper.convertD8toD10(tmpbkReader.readedXElement.getSingleText("signDate"));
//                                applyDate	申请日期	FixString(8)
                                items.applyDate = DateHelper.convertD8toD10(tmpbkReader.readedXElement.getSingleText("applyDate"));
//                                applyName	申请人名称	VarString(62)
                                items.applyName = tmpbkReader.readedXElement.getSingleText("applyName");
//                                ePayeeAcctName	接收人名称	VarString(62)
                                items.receName = tmpbkReader.readedXElement.getSingleText("ePayeeAcctName");
//                                redemptionOpenDate	回购起始日	FixString(8)
                                String redemptionOpenDate = tmpbkReader.readedXElement.getSingleText("redemptionOpenDate");
                                if (StringHelper.hasAnyChar(redemptionOpenDate)&&!"00000000".equals(redemptionOpenDate)) {
                                    items.repOpenDate = DateHelper.convertD8toD10(redemptionOpenDate);
                                }
//                                redemptionEndDate	回购到期日	FixString(8)
                                String redemptionEndDate = tmpbkReader.readedXElement.getSingleText("redemptionEndDate");
                                if (StringHelper.hasAnyChar(redemptionEndDate)&&!"00000000".equals(redemptionEndDate)) {
                                    items.repDueDate = DateHelper.convertD8toD10(redemptionEndDate);
                                }
//                                noPayReason	拒付理由	FixString(2)
//                                String noPayReason = tmpbkReader.readedXElement.getSingleText("recourseType");
//                                if (StringHelper.hasAnyChar(noPayReason)) {
//                                    if ("DC09".equals(noPayReason)) {
//                                        items.unPayCode = "99";
//                                    } else {
//                                        items.unPayCode = Integer.valueOf(noPayReason.substring(3)) + 1 + "";
//                                    }
//                                }
//                                recourseType	追索类型	FixString(4)
                                String recourseType = tmpbkReader.readedXElement.getSingleText("recourseType");
                                if (StringHelper.hasAnyChar(recourseType)&&!"-".equals(recourseType)) {
                                    items.recourseType = recourseType.equals("RT00") ? "1" : "2";
                                }
                                retAts.writeDetail(items);
                            }
                        } else {
                            throw new Exception(returnCode);
                        }
                    } else {
                        throw new Exception(tmpsbMsg.toString());
                    }
                } else {
                    throw new Exception(result[1]);
                }
            }while (tmpNowReadNum<totalNum);
        } catch (Exception e) {
            detail.respCode ="-1";
            detail.respInfo = e.getMessage();
            e.printStackTrace();
            retAts = new RetAtsB005BillBackQry(query.reqHeader);
            retAts.writeStart();
            retAts.writeDetail(detail);
        }
        retAts.writeEnd();

        return retAts;
    }

    @Override
    public RetAtsB006BillStateQry D_B006_BillState_Qeury(ReqB006BillStateQry query) throws Exception {
        RetAtsB006BillStateQry retAts = new RetAtsB006BillStateQry(query.reqHeader);
        retAts.writeStart();
        RetAtsB006BillStateQryDetail detail = new RetAtsB006BillStateQryDetail();
        Connection conn = FGBiz.getLocalDbConn();
        try{
            while (query.readRecord()){
                Map<String,Object> map = JDBCHelper.execQuerySingle(conn,SELECTRECEIPT,new Object[]{query.detail.reqSeqID});
                if(map==null || map.size()==0){
                    detail.respCode ="-1";
                    detail.respInfo = "状态码查询失败，请检查日志";
                    retAts.writeDetail(detail);
                    retAts.writeEnd();
                    return retAts;
                }
                String bustype = map.get("BUSITYPE").toString();
//              if(bustype!=null&&(bustype.equals("EE05")||bustype.equals("EE06")||bustype.equals("EE09")||bustype.equals("EE16")||bustype.equals("EE15"))) {
                if(StringHelper.isNullOrEmpty(bustype)){
                    throw new Exception("没有找到对应的操作记录："+query.detail.reqSeqID);
                }
                String isSign;
                if("2".equals(query.detail.operType)||"3".equals(query.detail.operType)){
                    isSign ="2";
                }else if("4".equals(query.detail.operType)){
                    isSign ="3";
                }else{
                    isSign ="1";
                }
                if(!bustype.equals("EE02")&&!bustype.equals("FE11"))
                {
                    detail = queryStateBy26(query, map,isSign);
                }else{
                    detail =queryStateBy28(query,map,isSign);
//                  detail = queryStateBy26(query, map);
                }
            }
        }catch (Exception e){
            detail.respCode ="-1";
            detail.respInfo = e.getMessage();
            e.printStackTrace();
        }
        retAts.writeDetail(detail);
        retAts.writeEnd();
        return retAts;
    }



    @Override
    public RetAtsB007BillKzsrQry D_B007_BillKzsr_Query(ReqB007BillKzsrQry query) throws Exception  {
        RetAtsB007BillKzsrQry retAts = new RetAtsB007BillKzsrQry(query.reqHeader);
        retAts.writeStart();
        String respCode ="";
        String respInfo ="";
        try{
            query.readRecord();
            //1代表追索，2代表非追索
            retAts.respCode = "0";
            retAts.respInfo = "";
            retAts.billNo = query.detail.billNo;
            retAts.writeRespInfos();
            for(int recoursetype=1;recoursetype<=2;recoursetype++){
                int numStart =1;
                int totalnum = 0;
                do {
                    XmlTextWriter xmlTextWriter = new XmlTextWriter();
                    SPDB01Header header = new SPDB01Header();
                    header.transCode = "EE29";
                    xmlTextWriter.writeStartElement("body");
                    //                transMasterID	交易客户号	FixString(10)	N	若输入则查询该客户号下的数据，若未输入则查询报文头客户号的数据
                    xmlTextWriter.writeElementString("transMasterID",getTransMasterID(query.detail.actNum));
                    //                billNo	电子票号	FixString(30）	Y	　
                    xmlTextWriter.writeElementString("billNo", query.detail.billNo);
                    //                recourseType	追索类型	FixString(4）	Y	RT00拒付追索RT01非拒付追索
                    if (1==recoursetype){
                        xmlTextWriter.writeElementString("recourseType","RT00" );
                    }else if(2==recoursetype){
                        xmlTextWriter.writeElementString("recourseType","RT01" );
                    }
                    //                beginNumber	起始记录数	FixString(4）	Y	　
                    xmlTextWriter.writeElementString("beginNumber", String.format("%4s", numStart));
                    //                queryNumber	查询记录数	FixString(4）	Y	　最大50
                    xmlTextWriter.writeElementString("queryNumber", String.format("%4s", 50));
                    xmlTextWriter.writeEndDocument();
                    String[] result = sendToBank(xmlTextWriter.toXmlString(), header);
                    if (result[0].length() == 0) {
                        StringBuilder tmpsbMsg = new StringBuilder();
                        XmlTextReader tmpbkReader = loadBankRespXmlReader(result[1], tmpsbMsg);
                        if (tmpbkReader != null) {
                            String returnCode = tmpbkReader.getFirstText("/packet/head/returnCode");
                            if (StringHelper.hasAnyChar(returnCode) && "AAAAAAA".equals(returnCode)) {
                                if (totalnum == -1) {
                                    totalnum = Integer.valueOf(tmpbkReader.getFirstText("/packet/body/totalNumber"));
                                }
                                if (tmpbkReader.read("/packet/body/lists/list")) {
                                    numStart++;
                                    RetAtsB007BillKzsrQryDetail detail = new RetAtsB007BillKzsrQryDetail();
                                    detail.receAct = tmpbkReader.readedXElement.getSingleText("acctNo");
                                    detail.receName = tmpbkReader.readedXElement.getSingleText("name");
                                    detail.receCode= tmpbkReader.readedXElement.getSingleText("orgId");
                                    detail.receBnkCode = tmpbkReader.readedXElement.getSingleText("bankNo");
                                    retAts.writeDetail(detail);
                                }
                            }else{
                                respCode = "-1";
                                respInfo = tmpbkReader.getFirstText("/packet/body/returnMsg");
                                break;
                            }
                        } else {
                            respCode = "-1";
                            respInfo = tmpsbMsg.toString();
                            break;
                        }
                    } else {
                        respCode = "-1";
                        respInfo = result[1];
                        break;
                    }
                }while (numStart<=totalnum);
            }
        }catch (Exception e){
            e.printStackTrace();
            respCode = "-1";
            respInfo = e.getMessage();
        }
        if("-1".equals(respCode)){
            retAts = new RetAtsB007BillKzsrQry(query.reqHeader);
            retAts.writeStart();
            retAts.respCode = respCode;
            retAts.respInfo = respInfo;
            retAts.billNo = query.detail.billNo;
            retAts.writeRespInfos();
        }
        retAts.writeEnd();
        return retAts;
    }

    @Override
    public RetAtsB008HistoricalBillQry D_B008_HistoricalBillQuery(ReqB008HistoricalBillQry query) throws Exception {
        RetAtsB008HistoricalBillQry retAts = new RetAtsB008HistoricalBillQry(query.reqHeader);
        retAts.writeStart();
        query.readRecord();
        int startNum = 1;
        int tmpNowReadNum = 0;
        int totalNum =0;
        try {
            do {
                XmlTextWriter xmlTextWriter = new XmlTextWriter();
                SPDB01Header header = new SPDB01Header();
                header.transCode = "EE24";
                xmlTextWriter.writeStartElement("body");
                xmlTextWriter.writeElementString("transMasterID",getTransMasterID(query.detail.actNum));
//            billNo	电子票号	FixString(30)	Y
                xmlTextWriter.writeElementString("billNo", query.detail.billNo);
//            eBillBusessType	查询类别（流转类别）	FixString(2)	Y
                String queryType = "";
                if("1".equals(query.detail.busiType)){
                    queryType ="02";
                }else if("2".equals(query.detail.busiType)){
                    queryType ="03";
                }else if("3".equals(query.detail.busiType)){
                    queryType ="04";
                }else if("10".equals(query.detail.busiType)){
                    queryType ="12";
                }
                xmlTextWriter.writeElementString("eBillBusessType", queryType);
//                transJnlNo	业务流水号	FixString(10)	N
                xmlTextWriter.writeElementString("transJnlNo", "");
//                beginNumber	起始记录数	FixNumber(4)	Y
                xmlTextWriter.writeElementString("beginNumber", "" + startNum);
//                queryNumber	查询记录数	FixNumber(4)	Y
                xmlTextWriter.writeElementString("queryNumber", "20");
                xmlTextWriter.writeEndDocument();
                String[] result = sendToBank(xmlTextWriter.toXmlString(), header);
                if (result[0].length() == 0) {
                    StringBuilder tmpsbMsg = new StringBuilder();
                    XmlTextReader tmpbkReader = loadBankRespXmlReader(result[1], tmpsbMsg);
                    if (tmpbkReader != null) {
                        String returnCode = tmpbkReader.getFirstText("/packet/head/returnCode");
                        if (StringHelper.hasAnyChar(returnCode) && "AAAAAAA".equals(returnCode)) {
                            if (totalNum == 0) {
                                totalNum = Integer.valueOf("/packet/body/totalNumber");
                            }
                            XElement billInfo = getBillInfo(query.detail.actNum,query.detail.billNo);
                            if (tmpbkReader.read("/packet/body/lists/list")) {
                                RetAtsB008HistoricalBillQryDetail items = new RetAtsB008HistoricalBillQryDetail();
                                startNum++;
                                tmpNowReadNum++;
                                String operAct ="";
                                if("1".equals(query.detail.queryType)){
                                    operAct = tmpbkReader.readedXElement.getSingleText("applyAcctNo");
                                }else{
//                                ePayeeAcctName	接收人名称	VarString(62)
                                    operAct = tmpbkReader.readedXElement.getSingleText("ePayeeAcctNo");
                                }
                                if(!query.detail.actNum.equals(operAct)){
                                    continue;
                                }
                                items.billNo = billInfo.getSingleText("billNo");
                                items.billNo = "AC01".equals(billInfo.getSingleText("eBillType"))?"1":"2";
                                items.billAmt = billInfo.getSingleText("eBillAmount");
                                items.issDate = DateHelper.convertD8toD10(billInfo.getSingleText("voteDate"));
                                items.dueDate = DateHelper.convertD8toD10(billInfo.getSingleText("expiryDate"));
                                items.transFlag ="EM00".equals(billInfo.getSingleText("canTransferFlag"))?"1":"0";

                                items.drawName = billInfo.getSingleText("eDrawerName");
                                items.drawAct = billInfo.getSingleText("eDrawerAcctNo");
                                items.drawBnkCode = billInfo.getSingleText("eDrawerBankNo");
                                items.drawBnkName = billInfo.getSingleText("drawerBankName");

                                items.accpName = billInfo.getSingleText("acceptorName");
                                items.accpAct = billInfo.getSingleText("acceptorAcctNo");
                                items.accpBnkCode = billInfo.getSingleText("acceptorBankNo");
                                items.accpBnkName = billInfo.getSingleText("acceptBankName");

                                items.payeeName = billInfo.getSingleText("ePayeeAcctName");
                                items.payeeAct = billInfo.getSingleText("ePayeeAcctNo");
                                items.payeeBnkCode = billInfo.getSingleText("ePayeeBankNo");
                                items.payeeBnkName = billInfo.getSingleText("payeeHostBankName");
                                items.billStatus = billInfo.getSingleText("eBillStatus");
                                retAts.writeDetail(items);
                            }
                        } else {
                            throw new Exception(returnCode);
                        }
                    } else {
                        throw new Exception(tmpsbMsg.toString());
                    }
                } else {
                    throw new Exception(result[1]);
                }
            }while (tmpNowReadNum<totalNum);
        } catch (Exception e) {
            e.printStackTrace();
            retAts = new RetAtsB008HistoricalBillQry(query.reqHeader);
            retAts.writeStart();
            retAts.respCode="-1";
            retAts.respInfo= e.getMessage();
        }
        retAts.writeAfter();
        return retAts;
    }

    @Override
    public RetAtsB009DrawBillQry D_B009_DrawBillQuery(ReqB009DrawBillQry query) throws Exception {
        return null;
    }

    @Override
    public RetAtsB010ProtocolStateQry D_B010_ProtocolStateQuery(ReqB010ProtocolStateQry query) throws Exception {
        return null;
    }

    @Override
    public RetAtsB011TransFlagQry D_B011_TransFlagQuery(ReqB011TransFlagQry query) throws Exception {
        return null;
    }

    //EE26
    private RetAtsB006BillStateQryDetail queryStateBy26(ReqB006BillStateQry query,Map<String,Object> map,String isSign) throws Exception{
        RetAtsB006BillStateQryDetail detail = new RetAtsB006BillStateQryDetail();
        XmlTextWriter xmlTextWriter = new XmlTextWriter();
        Connection conn =FGBiz.getLocalDbConn();
        String transCode = map.get("BUSITYPE").toString();
        String businessId = map.get("BANKREQSEQID").toString();
        SPDB01Header header = new SPDB01Header();
        header.transCode = "EE26";
        xmlTextWriter.writeStartElement("body");
//        transMasterID	交易客户号	FixNumber(10)		若输入则查询该客户号下的数据，若未输入则查询报文头客户号的数据
        xmlTextWriter.writeElementString("transMasterID",getTransMasterID(query.detail.actNum));
//        hostTxnCode	查询交易代码	FixString(4)	Y	交易代码
        xmlTextWriter.writeElementString("hostTxnCode",transCode);//查询交易代码(4)
        if("EE05".equals(transCode)){
            xmlTextWriter.writeElementString("businessId",businessId.split("_")[0]);//交易流水号(10)
        }else {
            xmlTextWriter.writeElementString("businessId", businessId);//交易流水号(10)
        }
//        beginNumber	起始记录数	FixNumber(4)	Y	最小1
        xmlTextWriter.writeElementString("beginNumber",String.format("%4s","1"));//起始记录数(4)
//        queryNumber	查询记录数	FixNumber(4)	Y	最大20笔
        xmlTextWriter.writeElementString("queryNumber",String.format("%4s","20"));//查询记录数(4)
        xmlTextWriter.writeEndDocument();
        String[] result = sendToBank(xmlTextWriter.toXmlString(),header);
        if(result[0].length() ==0){
            StringBuilder tmpsbMsg = new StringBuilder();
            XmlTextReader tmpbkReader = loadBankRespXmlReader(result[1],tmpsbMsg);
            if(tmpbkReader!=null){
//                totalNumber	总记录数	FixNumber(4)
//                循环
//                hostTxnCode	交易代码	FixString(4)
//                transDate	交易日期	FixString(8)
//                transJnlNo	业务流水号	FixString(20)
//                eBillBatchNo	网银批次号	FixString(18)		批量文件方式的业务可提供交易批次号，用于EE28查询
//                businessId	网银流水号	FixString(10)
//                eCDSFlag	ECDS报文标识号	FixString(35)
//                eCDSDate	ECDS报文日期时间	FixString(14)
//                billNo	电子票据序列号	 FixString(30)
//                eBillAmount	票面金额	FixString(13,2)
                String returnCode = tmpbkReader.getFirstText("/packet/head/returnCode");
                if(StringHelper.hasAnyChar(returnCode)&&"AAAAAAA".equals(returnCode)){
                    String totalNumber = tmpbkReader.getFirstText("/packet/body/totalNumber").trim();
                    if(!"1".equals(totalNumber)){
                        throw new Exception("明细记录获取失败,请稍后再查："+totalNumber);
                    }
                    if(tmpbkReader.read("/packet/body/lists/list")){
                        detail.respCode ="0";
                        detail.respInfo ="";
                        detail.reqSeqID =map.get("REQSEQID").toString();
                        String eBillJnlStatus = tmpbkReader.readedXElement.getSingleText("eBillJnlStatus");
                        detail.transState=isSign+"+"+eBillJnlStatus;
                        detail.payInfoCode=detail.transState;
                        //detail.billState =tmpbkReader.readedXElement.getSingleText("eBillStatus");
                        detail.billNo=tmpbkReader.readedXElement.getSingleText("billNo");
                        String billState=tmpbkReader.readedXElement.getSingleText("eBillStatus");
                        detail.billState ="-".equals(billState)?"":billState;
                        detail.busiNo =tmpbkReader.readedXElement.getSingleText("businessId");
                        if(StringHelper.hasAnyChar(eBillJnlStatus)&&!"2".equals(isSign)) {
                            if (!"1".equals(eBillJnlStatus) && !"4".equals(eBillJnlStatus)) {
                                if (!"EE05".equals(transCode)) {
                                    JDBCHelper.update(conn, DELETECANCEL, new Object[]{ businessId, query.detail.billNo, "1"});
                                } else {
                                    JDBCHelper.update(conn, DELETECANCEL, new Object[]{ businessId.split("_")[1], query.detail.billNo, "2"});
                                }
                            }
                        }
                    }
                }else{
                    detail.respCode="-1";
                    detail.respInfo = tmpbkReader.getFirstText("/packet/body/returnMsg").trim();
                }
            }else{
                detail.respCode ="-1";
                detail.respInfo=tmpsbMsg.toString();
            }
        }else
        {
            detail.respCode ="-1";
            detail.respInfo = result[1];
        }
        return detail;
    }


    //EE28
    private RetAtsB006BillStateQryDetail queryStateBy28(ReqB006BillStateQry query, Map<String, Object> map,String isSign)throws Exception {
        RetAtsB006BillStateQryDetail detail = new RetAtsB006BillStateQryDetail();
        XmlTextWriter xmlTextWriter = new XmlTextWriter();
        String businessId = map.get("BANKREQSEQID").toString();
        String transdate = map.get("TRANSDATE").toString();

        SPDB01Header header = new SPDB01Header();
        header.transCode = "EE28";
        xmlTextWriter.writeStartElement("body");
//        transMasterID	交易客户号	FixString(10)	N	若输入则查询该客户号下的数据，若未输入则查询报文头客户号的数据
        xmlTextWriter.writeElementString("transMasterID",getTransMasterID(query.detail.actNum));
//        eBillBatchNo	批次号	FixString(18)	Y
        xmlTextWriter.writeElementString("eBillBatchNo",transdate+businessId);
//        businessType	查询类别	FixString(2)	N	01-请求中 02-审批同意
//        xmlTextWriter.writeElementString("businessType","01");
//        出票登记与贴现时可以选择输入，其他交易默认为01请求中
//        beginNumber	起始记录数	FixNumber(4)	Y	最小为1
//        xmlTextWriter.writeElementString("beginNumber",String.format("%4s","1"));
        xmlTextWriter.writeElementString("beginNumber","1");
//        queryNumber	查询记录数	FixNumber(4)	Y	最大为20
//        xmlTextWriter.writeElementString("queryNumber",String.format("%4s","1"));
        xmlTextWriter.writeElementString("queryNumber","20");
        xmlTextWriter.writeEndDocument();
        String[] result = sendToBank(xmlTextWriter.toXmlString(),header);
        if(result[0].length() ==0){
            StringBuilder tmpsbMsg = new StringBuilder();
            XmlTextReader tmpbkReader = loadBankRespXmlReader(result[1],tmpsbMsg);
            if(tmpbkReader!=null){
                String returnCode = tmpbkReader.getFirstText("/packet/head/returnCode");
                if(StringHelper.hasAnyChar(returnCode)&&"AAAAAAA".equals(returnCode)){
                    String totalNumber = tmpbkReader.getFirstText("/packet/body/totalNumber").trim();
                    if(!"1".equals(totalNumber)){
                        throw new Exception("返回的数据不唯一："+totalNumber);
                    }
                    if(tmpbkReader.read("/packet/body/lists/list")){
                        detail.respCode ="0";
                        detail.respInfo ="";
//                        detail.reqSeqID =map.get("REQSEQID").toString();
//                        00-未处理  01-处理成功  02-处理失败 03 已发送 04-处理中
                        //                        05-银行审核中 06-被银行拒绝


                        detail.transState=tmpbkReader.readedXElement.getSingleText("status");
                        if("01".equals(detail.transState)){
                            String billNo = tmpbkReader.readedXElement.getSingleText("billNo");
                            detail.billNo = "-".equals(billNo)?"":billNo;
                            String billStatus = tmpbkReader.readedXElement.getSingleText("eBillStatus");
                            detail.billState ="-".equals(billStatus)?"":billStatus;
                            if((StringHelper.isNullOrEmpty(detail.billNo)||StringHelper.isNullOrEmpty(detail.billState))&&"01".equals(detail.transState)){
                                detail.transState = "00";
                            }
                        }
                        detail.payInfoCode=detail.transState;
//                        detail.billState = tmpbkReader.readedXElement.getSingleText("eBillStatus");
                    }
                }else{
                    detail.respCode="-1";
                    detail.respInfo = tmpbkReader.getFirstText("/packet/body/returnMsg").trim();
                }
            }else{
                detail.respCode ="-1";
                detail.respInfo=tmpsbMsg.toString();
            }
        }else
        {
            detail.respCode ="-1";
            detail.respInfo = result[1];
        }
        return detail;
    }

    private XElement getBillInfo(String actNum, String billNo)throws Exception{
        XmlTextWriter xmlTextWriter = new XmlTextWriter();
        SPDB01Header header = new SPDB01Header();
        header.transCode = "EE22";
        xmlTextWriter.writeStartElement("body");
        xmlTextWriter.writeElementString("transMasterID",getTransMasterID(actNum));
//            billNo	电子票号	FixString(30)	Y
        xmlTextWriter.writeElementString("billNo", billNo);
        xmlTextWriter.writeEndDocument();
        String[] result = sendToBank(xmlTextWriter.toXmlString(), header);
        if (result[0].length() == 0) {
            StringBuilder tmpsbMsg = new StringBuilder();
            XmlTextReader tmpbkReader = loadBankRespXmlReader(result[1], tmpsbMsg);
            if (tmpbkReader != null) {
                String returnCode = tmpbkReader.getFirstText("/packet/head/returnCode");
                if (StringHelper.hasAnyChar(returnCode) && "AAAAAAA".equals(returnCode)) {
                    tmpbkReader.read("/packet/body");
                    return tmpbkReader.readedXElement;
                } else {
                    throw new Exception(returnCode);
                }
            } else {
                throw new Exception(tmpsbMsg.toString());
            }
        } else {
            throw new Exception(result[1]);
        }
    }
}
